package com.zqxq.lottery.service.sys.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.zqxq.common.utils.DispatcherUtils;
import com.zqxq.lottery.service.sys.ISysMsgService;
import com.zqxq.lottery.entity.po.sys.SysMsgPO;
import com.zqxq.lottery.mapper.sys.SysMsgMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;


@Service
@Slf4j
public class SysMsgServiceImpl extends ServiceImpl<SysMsgMapper,SysMsgPO> implements ISysMsgService {

    @Autowired
    private SysMsgMapper sysMsgMapper;
    @Override
    public void updateMsg() {
        /*List<Map<String,Object>> list = sysMsgMapper.getTop10WinPrize();
        for(int i=0;i<10;i++){
            Map<String,Object> map = list.get(i);
            String mobile = String.valueOf(map.get("mobile"));
            String lotteryId = "21";
            BigDecimal prize = new BigDecimal(String.valueOf(map.get("prize"))).setScale(2,BigDecimal.ROUND_UP);
            mobile = mobile.substring(0,3)+"****"+mobile.substring(7,11);
            String lotteryType = "";
            switch (lotteryId) {
                case "11":
                    //双色球
                    lotteryType = "双色球";
                    break;
                case "12":
                    //福彩3D
                    lotteryType = "福彩3D";
                    break;
                case "14":
                    //大乐透
                    lotteryType = "大乐透";
                    break;
                case "15":
                    //七星彩
                    lotteryType = "七星彩";
                    break;
                case "16":
                    //排列三
                    lotteryType = "排列三";
                    break;
                case "21":
                    //竞猜足球
                    lotteryType = "竞猜足球";
                    break;
            }
            String content = "羡慕，"+mobile+"中得竞猜足球"+prize+"趣豆！";
            SysMsgPO po = new SysMsgPO();
            po.setId(DispatcherUtils.parseLong(i+1));
            po.setContent(content);
            if(prize.compareTo(BigDecimal.ZERO)==1){
                baseMapper.updateById(po);
            }
        }*/
        List<Map<String,Object>> list = sysMsgMapper.getTop10Exchange();
        for(int i=0;i<list.size();i++){
            Map<String,Object> map = list.get(i);
            String mobile = String.valueOf(map.get("mobile"));
            String productName = String.valueOf(map.get("productName"));
            mobile = mobile.substring(0,3)+"****"+mobile.substring(7,11);
            Integer prize = new BigDecimal(String.valueOf(map.get("num"))).intValue();
            String content = mobile+"成功兑换了"+prize+"钻的"+productName;
            SysMsgPO po = new SysMsgPO();
            po.setId(DispatcherUtils.parseLong(i+1));
            po.setContent(content);
            if(prize>0){
                baseMapper.updateById(po);
            }
        }

    }

}
